package com.cybertooth.dbconvenience.query.columns;

import com.cybertooth.dbconvenience.query.enums.AggregateFunction;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.Mockito.*;

/**
 * <p></p>
 *
 * @author dnelson
 */
public class WhenAggregateColumnIsCreated {

	@Test
	public void toSqlOutputIsCorrect() {
		// TODO: test injection
		final String columnName = "column_name";
		final String fieldName = "columnName";
		ColumnNameTransformer t = mock(ColumnNameTransformer.class);
		when(t.transform(columnName)).thenReturn(fieldName);

		AggregateColumn c = new AggregateColumn(t);
		c.column = new Column(columnName);
		c.function = AggregateFunction.AVG;

		assertThat(c.toSql().trim(), is("AVG(" + columnName + ") AS " + fieldName));
	}
}
